package com.yunc.modules.sys.handler;

import com.yunc.common.message.AbstractMessageHandler;
import com.yunc.modules.sys.entity.SysLoginLog;
import com.yunc.modules.sys.service.ISysLoginLogService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author taocongcong
 * @create 2018-11-21 14:26
 */
@Service
public class LoginLogHandler extends AbstractMessageHandler<SysLoginLog> {

    private static final Logger logger = LogManager.getLogger(AbstractMessageHandler.class);

    @Autowired
    private ISysLoginLogService sysLoginLogService;

    public LoginLogHandler() {
        super("LOGIN_LOG_SYS", SysLoginLog.class);
    }

    @Override
    public void handle(SysLoginLog loginLog) {
        sysLoginLogService.save(loginLog);
    }

    @Override
    public void handleFailed(SysLoginLog obj) {
        StringBuilder sb = new StringBuilder();
        sb.append("msg:[").append(obj).append("], 超过失败次数，停止重试。");
        logger.warn(sb.toString());
    }
}
